<template>
  <div class="auto form-horizontal" >
    <modal :show.sync="show"  v-ref:modal backdrop="false">
      <header slot="modal-header" class="modal-header">
        <h3 style="color:black" class="modal-title">其他收费发票</h3>
      </header>
      <article slot="modal-body" style = "padding-bottom:10px; margin-left:20px" id="testbill">
          <table>
            <tr>
              <td rowspan="4">购买方</td>
              <td></td>
            </tr>
            <tr>
              <td></td>
              <td></td>
            </tr>
            <tr>
              <td></td>
              <td></td>
            </tr>
            <tr>
              <td></td>
              <td></td>
            </tr>
          </table>
      </article>
      <footer slot="modal-footer" class="modal-footer">
        <div class="col-xs-5" v-if="messShow">
          <span style="color: red"><strong>未获取到收据代码，发票不能正常打印，请确认后补打发票</strong></span>
        </div>
        <div class="col-sm-2" v-if="!messShow">
          <span><strong>发票号:{{model.f_bill_id}}</strong></span>
        </div>
        <report-print id='testbill' top='1cm' left='2cm' width='100%' height='100%' v-if= 'bill.data && model.f_bill_id'></report-print>
        <button type="button" class="btn btn-default" @click='cancel()'>取消</button>
      </footer>
    </modal>
  </div>
</template>
<script>
import * as Util from '../../../components/Util'
import { DataModel } from 'vue-client'
export default {
  title: '其他收费发票',
  data () {
    return {
      model: {
        f_bill_id: ''
      },
      bill: new DataModel('rs/report/other_bill'),
      messShow: false
    }
  },
  props: ['show', 'row', 'logic'],
  ready () {
    let tablename = 't_billcollec'
    let condition = 'f_user = ' + "'" + Util.f.name + "'" + ' and f_bill_state = ' + "'" + '启用' + "'"
    this.$SqlService.singleTable(tablename, condition).then((res) => {
      this.model.f_bill_id = res.data[0].f_bill_id
      this.model.f_billcoll_id = res.data[0].id
    }).catch((error) => {
      this.messShow = true
    })
  },
  methods: {
    cancel  () {
      this.$dispatch('toggle')
    }
  },
  events: {
    'print-success' () {
      this.model = Object.assign(this.model, this.logic)
      this.$PrintService.modifyBillNumber(this.model, this.data).then((res) => {
        this.$dispatch('success', '发票打印', this.data, res)
      }).catch((error) => {
        this.$dispatch('error', '发票打印', this.data, error)
      })
    },
    'print-error' () {
      this.$dispatch('error', '发票打印', this.data, null)
    }
  }
}

</script>
<style >
</style>
